package com.crimsec.utils.dinfo;

import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import static java.lang.System.*;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author moroz
 */
public class CharsetsM implements FileFilter {

    public static OutputStream os1;

    public static void main(String[] args) {
        for (Locale l : Locale.getAvailableLocales()) {
            out.println(l.getDisplayName());
        }

        File tmpd = new File("/tmp/a");
        try {

            OutputStream os = new FileOutputStream(new File(tmpd, "aaa"));
            os.write("что-то длинное по русски".getBytes());
            os.write("\n\n".getBytes());
            os.write("что-то длинное по русски".getBytes("CP1251"));
            os.write("\n\n".getBytes());
            os.write("что-то длинное по русски".getBytes("CP866"));
            os.flush();
            os.close();

            /*

             String fn = new String("На 1251 строка".getBytes("UTF-8"), "CP1251");

             File f1 = new File(tmpd, fn);
             boolean a = f1.createNewFile();
             out.println(a);
             */
            os1 = new FileOutputStream(new File(new File("/tmp/a"), "bbb"));

            CharsetsM cm = new CharsetsM();
            File[] files = tmpd.listFiles(cm);
            os1.flush();
            os1.close();
            for (File f : files) {
                //  out.println(f.getName());
            }



        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public boolean accept(File pathname) {
        try {

            os1.write(pathname.getName().getBytes());
            os1.write("\n\n".getBytes());

            String n = new String(pathname.getName().getBytes(), "CP1251");
            out.println("en:" + n);
            //     out.println(n);

//            String en = new String(n.getBytes(), "CP1251");

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return true;
    }
}
